package practice_list;

/**
 * Created with Intellij JDEA
 * Description:
 * User:
 * Date:2022-03-22
 * Time:15:07
 */
public class 删除排序链表中的重复元素II {

    public ListNode deleteDuplicates(ListNode head) {

        ListNode prev = new ListNode(0,head);
        ListNode cur = prev;

        while (cur.next != null && cur.next.next != null) {

            if (cur.next.val == cur.next.next.val) {
                int tmp = cur.next.val;
                while (cur.next != null && cur.next.val == tmp) {
                    cur.next = cur.next.next;
                }
            }else{
                cur = cur.next;
            }
        }

        return prev.next;
    }
}
